    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    $(document).ready(function(){
        $("#tabs").tabs();
            
        $(".button").button();

        $('input[name=create]').click(function() {
            if ($('#create input[name=link]').val() == '') {
                    $('#create .alert').slideDown();
                    $('#create input[name=link]').css('border-color', 'red');
            } else {
                $('#createLink').html();
                $('#create .loader').show();
                
                $.post(
                    'index.php',
                    {
                        task:  'create',
                        link: $('#create input[name=link]').val(),
                        alias: $('#create input[name=alias]' ).val()
                    },
                    function(data) {
                        $('#create .loader').hide();
                        $('#createLink').slideDown();
                        $('#createLink .msg').html('Your new link "'+ data +'"');
                    }
                );
            }
        });

        $('input[name=signup]').click(function() {
            if ($('#signup input[name=email]').val() == '' ||
                $('#signup input[name=pass]' ).val() == '') {
                    $('#signup .alert').slideDown();
                    $('#signup input[type=text]').css('border-color', 'red');
            } else {
                $('#signupLink').hide();
                $('#signup .loader').show();
                
                $.post(
                    'index.php',
                    {
                        task:  'login',
                        email: $('#signup input[name=email]').val(),
                        pass:  $('#signup input[name=pass]' ).val()
                    },
                    function(data) {
                        $('#signup .loader').hide();
                        $('#signupLink').slideDown();
                        $('#signupLink .msg').html('You are sign up with name "'+ $('#signup input[name=email]').val() +'" and pass "'+ $('#signup input[name=pass]').val() +'" (data returned = "'+ data +'")');
                    }
                );
            }
        });

        $('a[name=forgot]').click(function() {
            if ($('#signup input[name=email]').val() == '') {
                $('#signup .alert').slideDown();
                $('#signup input[name=email]').css('border-color', 'red');
            } else {
                $('#signupLink').hide();
                $('#signup .loader').show();
                
                $.post(
                    'index.php',
                    {
                        task:  'forgot',
                        email: $('#signup input[name=email]').val()
                    },
                    function(data) {
                        $('#signup .loader').hide();
                        $('#signupLink').slideDown();
                        $('#signupLink .msg').html('Your new pass sended to email "'+ $('#signup input[name=email]').val() +'" (data returned = "'+ data +'")');
                    }
                );
            }
        });
        
        $('input[name=register]').click(function() {
            if ($('#register input[name=email]').val() == '' ||
                $('#register input[name=pass]' ).val() == '') {
                    $('#register .alert').slideDown();
                    $('#register input[type=text]').css('border-color', 'red');
            } else {
                $('#registerLink').hide();
                $('#register .loader').show();
                
                $.post(
                    'index.php',
                    {
                        task:  'register',
                        email: $('#register input[name=email]').val(),
                        pass:  $('#register input[name=pass]' ).val()
                    },
                    function(data) {
                        if (data == 'success') {
                            $('#register .loader').hide();
                            $('#registerLink').slideDown();
                            $('#registerLink .msg').html('You are registered with email "'+ $('#register input[name=email]').val() +'"');
                        } else {
                            alert(data);
                        }
                    }
                );
            }
        });
    });

